<h2>Gestion des paramètres</h2>

<?= form_open('admin/config/update_settings', 'class="stylized"') ?>

<?php

$previous_namespace = null;
foreach ($settings as $setting) {
	$id = 'setting_'.$setting->id;
	if ($setting->namespace != $previous_namespace) {
		if ($previous_namespace != null) { ?>
			</table>
			</fieldset>
		
		<?php } ?>
		
		<fieldset>
			<legend><?= $this->ApplicationConfig->titlelize_namespace($setting->namespace) ?></legend>
			<table>
		
		<?php
	}
	echo '<tr>';
	echo '<td>'.form_label($setting->label, $id).' :</td>';
	echo '<td>';
	switch ($setting->value_type) {
		case 'T_INT':
			echo form_number($id, $setting->value, 'id="'.$id.'"');
			break;
		case 'T_STRING':
			echo form_input($id, $setting->value, 'id="'.$id.'"');
			break;
		case 'T_DATETIME':
			echo form_input($id, $setting->value, 'id="'.$id.'" class="js-datetime"');
			break;
		case 'T_BOOL':
			echo form_checkbox($id, 1, $setting->value, 'id="'.$id.'"');
			break;
		case 'T_TEXT':
			echo form_textarea($id, $setting->value, 'id="'.$id.'"');
			break;
	}
	echo form_hidden('reset_'.$id, $setting->default_value);
	echo js_link($setting, 'setting_reset', icon_tag('reset'), 'Restaurer la valeur par défaut');
	echo ' ';
	echo js_link($setting, 'setting_save', icon_tag('database_save'), 'Enregistrer');
	echo '</td>';
	echo '</tr>';
	$previous_namespace = $setting->namespace;
}
?>
	</table>
	</fieldset>
</form>

<p>
	<?php if ($advanced_view) {
		echo icon_tag('brick_delete').'  Voir les '.anchor('admin/config/settings', 'paramètres de base').' uniquement';
	}
	else {
		echo icon_tag('brick_add').'  Voir les '.anchor('admin/config/advanced_settings', 'paramètres avancés').' - je ferai attention, promis !';
	} ?>
</p>
